/**
 * Copyright ©2012-2018 HopeHaiyang Corporation, All Rights Reserved
 * http://www.wuhanhope.com
 */
package hope.platform.data.web;

import hope.platform.data.domain.SiteInfo;
import hope.platform.data.server.data.header.SiteInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * class info
 *
 * @author hujia
 *         Create at 2018/7/11 9:23
 */
@RestController
@RequestMapping("/siteInfo")
public class SiteInfoController {

    @Autowired
    private SiteInfoService siteInfoService;

    @RequestMapping(method = RequestMethod.POST)
    public SiteInfo addSiteInfo(@RequestBody SiteInfo siteInfo) throws Exception {
        if(siteInfo.getSerialNumber().toString().length()!= 7){
            throw new Exception("serialNumber is not right.");
        }
        return siteInfoService.addSiteInfo(siteInfo);
    }

    @RequestMapping(value = "/all", method = RequestMethod.GET)
    public List<SiteInfo> getSiteInfoAll() throws Exception {
        return siteInfoService.getAllSiteInfo();
    }

    @RequestMapping(value = "/serialNumber/{serialNumber}", method = RequestMethod.GET)
    public SiteInfo getSiteInfoBySerialNumber(@PathVariable String serialNumber) throws Exception {
        return siteInfoService.getSiteInfoBySerialNumber(serialNumber);
    }

    @RequestMapping(value = "/siteType/{siteType}",method = RequestMethod.GET)
    public List<SiteInfo> getSiteInfoBySiteType(@PathVariable String siteType) throws Exception {
        return siteInfoService.getSiteInfoBySiteType(siteType);
    }

    @RequestMapping(method = RequestMethod.PUT)
    public SiteInfo updateSiteInfo(@RequestBody SiteInfo siteInfo) throws Exception{
        return siteInfoService.updateSiteInfo(siteInfo);
    }


}
